package com.ee.chat.api.controller;

import com.ee.chat.api.service.IHostService;
import com.ee.chat.common.bean.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("host")
public class HostController {
    private Logger log = LoggerFactory.getLogger(HostController.class);

    @Resource
    IHostService hostService;

    /**
     * 获取头衔主播列表
     * @Author Shane
     * @Date 2019/7/2511:22
     * @param 
     * @return
     **/
    @RequestMapping("getTitleHosts")
    public Result getTitleHosts(@RequestParam(required = false) String token, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit){
        try {
            return hostService.getTitleHosts(token, page, limit);
        } catch (Exception e){
            log.error("【获取头衔主播列表错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取banner列表
     * @Author Shane
     * @Date 2019/7/2511:23
     * @param
     * @return
     **/
    @RequestMapping("getBanners")
    public Result getBanners(@RequestParam(required = false) String token){
        try {
            return hostService.getBanners(token);
        } catch (Exception e){
            log.error("【获取banner列表错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取主播列表
     * @Author Shane
     * @Date 2019/7/2511:46
     * @param type  类型，0-热门  1-在线  2-新人  3-关注  4-同城  5-粉丝
     * @param location  用户经纬度
     * @return
     **/
    @RequestMapping("getTypeHosts")
    public Result getHosts(@RequestParam(required = false) String token, @RequestParam Integer type, @RequestParam(required = false) String location,
                           @RequestParam(defaultValue = "1") Integer page,
                           @RequestParam(defaultValue = "10") Integer limit,
                           @RequestParam(required = false) String extra){
        try {
            return hostService.getTypeHosts(token, type, page, limit, location, extra);
        } catch (Exception e){
            log.error("【获取主播列表错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 随机获取在线主播
     * @Author AppiJ
     * @Date 2020/11/13 11:56
     * @param
     * @return
     */
    @RequestMapping("getRandomOnlineHost")
    public Result getRandomOnlineHost(@RequestParam(required = false) String token){
        try {
            return hostService.getRandomOnlineHost(token);
        } catch(Exception e){
            log.error("【随机获取在线主播错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 同城打招呼
     * @Author Shane
     * @Date 2020/4/20 17:53
     * @param toUserId  对方id
     * @return
     */
    @RequestMapping("sayHello")
    public Result sayHello(@RequestParam String token, @RequestParam Integer toUserId){
        try {
            return hostService.sayHello(token, toUserId);
        } catch (Exception e){
            log.error("【打招呼错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取主播招呼用语
     * @Author Shane
     * @Date 2019/7/28 22:05
     * @param status    状态，0-包含待审核的
     * @return
     */
    @RequestMapping("getHostCallContents")
    public Result getHostCallContents(@RequestParam String token, Integer status,
                                      @RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10") Integer limit){
        try {
            return hostService.getHostCallContents(token, status, page, limit);
        } catch (Exception e){
            log.error("【获取招呼用语错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取用户操作记录
     * @Author Shane
     * @Date 2019/7/28 22:53
     * @param
     * @return
     */
    @RequestMapping("getUserOperations")
    public Result getUserOperations(@RequestParam String token, @RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10") Integer limit){
        try {
            return hostService.getUserOperations(token, page, limit);
        } catch (Exception e){
            log.error("【获取用户操作记录错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 主播打招呼
     * @Author Shane
     * @Date 2019/8/11 20:57
     * @param operationLogId    记录id
     * @param contentId         招呼内容id
     * @return
     */
    @RequestMapping("callUser")
    public Result callUser(@RequestParam String token, @RequestParam Integer operationLogId, @RequestParam Integer contentId){
        try {
            return hostService.callUser(token, operationLogId, contentId);
        } catch(Exception e){
            log.error("【主播打招呼错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取用户主页简略信息
     * @Author Shane
     * @Date 2019/8/1 23:07
     * @param toUserId    用户id
     * @return
     */
    @RequestMapping("getUserHomeBrief")
    public Result getUserHomeBrief(@RequestParam String token, @RequestParam Integer toUserId){
        try {
            return hostService.getUserHomeBrief(token, toUserId);
        } catch(Exception e){
            log.error("【获取用户主页简略信息错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取用户主页信息
     * @Author Shane
     * @Date 2019/7/28 23:12
     * @param toUserId 主播id
     * @return
     */
    @RequestMapping("getUserHome")
    public Result getUserHome(@RequestParam(required = false) String token, @RequestParam Integer toUserId){
        try {
            return hostService.getUserHome(token, toUserId);
        } catch(Exception e){
            log.error("【获取用户主页信息错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取用户资料
     * @Author Shane
     * @Date 2019/7/2912:14
     * @param toUserId    用户id
     * @return
     **/
    @RequestMapping("getUserInfo")
    public Result getUserInfo(@RequestParam(required = false) String token, @RequestParam Integer toUserId){
        try {
            return hostService.getUserInfo(token, toUserId);
        } catch(Exception e){
            log.error("【获取用户资料错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取主播评价列表
     * @Author Shane
     * @Date 2019/8/115:54
     * @param hostUserId    主播id
     * @return
     **/
    @RequestMapping("getHostEvaluates")
    public Result getHostEvaluates(@RequestParam String token, @RequestParam Integer hostUserId, @RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer limit){
        try {
            return hostService.getHostEvaluates(token, hostUserId, page, limit);
        } catch(Exception e){
            log.error("【获取主播评价错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取用户动态
     * @Author Shane
     * @Date 2019/7/2912:15
     * @param toUserId    用户id
     * @return
     **/
    @RequestMapping("getUserDynamic")
    public Result getUserDynamic(@RequestParam(required = false) String token, @RequestParam Integer toUserId, @RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer limit){
        try {
            return hostService.getUserDynamic(token, toUserId, page, limit);
        } catch(Exception e){
            log.error("【获取主播动态错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 搜索
     * @Author Shane
     * @Date 2019/10/10 22:12
     * @param keyword   查询关键字
     * @return
     */
    @RequestMapping("search")
    public Result search(@RequestParam(required = false) String token, String keyword, @RequestParam(defaultValue = "1") Integer page,
                         @RequestParam(defaultValue = "10") Integer limit){
        try {
            return hostService.search(token, keyword, page, limit);
        } catch(Exception e){
            log.error("【搜索错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取用户动态
     * @Author Shane
     * @Date 2020/8/19 15:23
     * @param 
     * @return 
     */
    @RequestMapping("getUserOperationLog")
    public Result getUserOperationLog(@RequestParam String token, @RequestParam(required = false) Integer curr){
        try {
            return hostService.getUserOperationLog(token, curr);
        } catch(Exception e){
            log.error("【获取用户动态错误】", e);
        }
        return Result.returnFailure();
    }


}
